package com.taxi.driver.data.duty.local;

import android.text.TextUtils;

import com.qianxx.utils.SP;
import com.taxi.driver.config.DutyStatus;
import com.taxi.driver.data.duty.DutySource;
import com.taxi.driver.data.entity.OrderListenerEntity;

import javax.inject.Inject;

import rx.Observable;

/**
 * 功能描述：
 */
public class DutyLocalSource implements DutySource {

    // 用于本地存储
    private SP mSP;
    // 是否工作状态
    private Boolean mWork;

    @Inject
    public DutyLocalSource(SP sp) {
        mSP = sp;
    }

    @Override
    public Observable<String> reqDutyStatus(boolean onlyFromRemote) {
        if (mWork == null) {
            return Observable.empty();
        }
        return Observable.just(mWork ? DutyStatus.ON_DUTY : DutyStatus.OFF_DUTY);
    }

    @Override
    public Observable<String> reqOnDuty(double onWorkLng, double onWorkLat, String uploadText) {
        return null;
    }

    @Override
    public Observable<String> reqOffDuty(double offWorkLng, double offWorkLat, String uploadText) {
        return null;
    }

    @Override
    public void setWorkStatus(Boolean isWork) {
        mWork = isWork;
    }

    @Override
    public Boolean isWork() {
        return mWork;
    }

    @Override
    public void saveListenerSetting(String driverUuid, OrderListenerEntity entity) {
        if (entity == null || TextUtils.isEmpty(driverUuid)) return;
        mSP.putObject("set-" + driverUuid, entity); //保存到本地
    }

    @Override
    public OrderListenerEntity getListenerSetting(String driverUuid) {
        if (TextUtils.isEmpty(driverUuid)) return new OrderListenerEntity();
        // 如果要在该类中"缓存听单设置"，在退出登录时 需"清除缓存"
        OrderListenerEntity entity = mSP.getObject("set-" + driverUuid, OrderListenerEntity.class);
        if (entity == null) entity = new OrderListenerEntity();
        return entity;
    }

    @Override
    public Observable<OrderListenerEntity> reqListenerSetting(String driverUuid) {
        return null;
    }

    @Override
    public Observable<String> reqSaveListenerSetting(int remindType, String appointTimeStart, String appointTimeEnd) {
        return null;
    }
}
